//
//  MYStatusRetweetedView.m
//  MYChatting
//
//  Created by mac on 16/8/25.
//  Copyright © 2016年 lhf. All rights reserved.
//

#import "MYStatusRetweetedView.h"
#import "Status.h"
#import "MYStatusPictureView.h"
#import "Masonry.h"
#import "User.h"

@interface MYStatusRetweetedView ()

@property (nonatomic,weak) UILabel *retweetedLabel;
@property (nonatomic,weak) MYStatusPictureView *pictureView;

//设置约束
@property (nonatomic,weak) MASConstraint *bottomConstraint;

@end

@implementation MYStatusRetweetedView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
        [self setUpUI];
        
    }
    return self;
}



- (void)setUpUI{
    
    UILabel *retweetedLabel = [[UILabel alloc] init];
    retweetedLabel.numberOfLines = 0;
    retweetedLabel.preferredMaxLayoutWidth = kScreenWidth - 2 * 12;
    [self addSubview:retweetedLabel];
    [retweetedLabel sizeToFit];
    self.retweetedLabel = retweetedLabel;
    
    MYStatusPictureView *pictureView = [[MYStatusPictureView alloc] init];
    [self addSubview:pictureView];
    self.pictureView = pictureView;
    
    [retweetedLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self).offset(12);
    }];
    
    [pictureView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(retweetedLabel.mas_bottom).offset(12);
        make.left.equalTo(retweetedLabel.mas_left);
    }];
    
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
       self.bottomConstraint =  make.bottom.equalTo(pictureView.mas_bottom).offset(12);
    }];
    
}


- (void)setRetweetedStatus:(Status *)retweetedStatus{
    _retweetedStatus = retweetedStatus;
    
    
    self.retweetedLabel.text = [NSString stringWithFormat:@"@%@%@",retweetedStatus.user.name,retweetedStatus.text];
    self.pictureView.pic_urls = retweetedStatus.pic_urls;
    
    [self.bottomConstraint uninstall];
    if (retweetedStatus.pic_urls.count > 0) {
        [self mas_updateConstraints:^(MASConstraintMaker *make) {
            self.bottomConstraint = make.bottom.equalTo(self.pictureView.mas_bottom).offset(12);
        }];
    }else{
        [self mas_updateConstraints:^(MASConstraintMaker *make) {
            self.bottomConstraint = make.bottom.equalTo(self.retweetedLabel.mas_bottom).offset(12);
        }];
    }
}

@end
